﻿using System;

namespace FxCore.Base
{
    public class TilePoint
    {
        public long TileX { get; }

        public long TileY { get; }

        public TilePoint()
        {
            this.TileX = 0L;
            this.TileY = 0L;
        }

        public TilePoint(long tileX, long tileY)
        {
            this.TileX = tileX;
            this.TileY = tileY;
        }

        public static bool operator ==(TilePoint pointA, TilePoint pointB)
        {
            if (pointA == null || pointB == null)
            {
                throw new NullReferenceException();
            }

            return pointA.TileX == pointB.TileX && pointA.TileY == pointB.TileY;
        }

        public static bool operator !=(TilePoint pointA, TilePoint pointB)
        {
            return !(pointA == pointB);
        }

        public static TilePoint operator +(TilePoint pointA, TilePoint pointB)
        {
            return new TilePoint(pointA.TileX + pointB.TileX, pointA.TileY + pointB.TileY);
        }

        public static TilePoint operator -(TilePoint pointA, TilePoint pointB)
        {
            return new TilePoint(pointA.TileX - pointB.TileX, pointA.TileY - pointB.TileY);   
        }

        public override string ToString()
        {
            return $"瓦片坐标:{{TileX=>{this.TileX}, TileY=>{this.TileY}}}";
        }

        public override int GetHashCode()
        {
            return this.TileX.GetHashCode() ^ this.TileY.GetHashCode();
        }

        public override bool Equals(object obj)
        {
            TilePoint tmp = (TilePoint) obj;
            if (tmp == null)
            {
                throw new NullReferenceException(nameof(obj) + "为Null");
            }

            return tmp.TileX == this.TileX && tmp.TileY == this.TileY;
        }
    }
}
